package com.example.onlineeducation.viewmodel


import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import com.example.onlineeducation.repository.UserRepository
import com.example.onlineeducation.base.BaseViewModel
import com.example.onlineeducation.data.constant.Constants
import com.example.onlineeducation.data.entity.LoginUserInfoEntity
import com.example.onlineeducation.data.json.UserInfoJson
import com.yc.jetpacklib.net.YcResult
import kotlinx.coroutines.flow.collectLatest


/**
 * Creator: yc
 * Date: 2021/6/15 18:03
 * UseDes:
 */
class LoginConfirmVM : BaseViewModel() {

    private val mUserRepository: UserRepository by lazy { UserRepository(mApiService) }

    private val _mUerInfo = MutableLiveData<YcResult<LoginUserInfoEntity>>()
    val mUerInfo: LiveData<YcResult<LoginUserInfoEntity>> = _mUerInfo

    fun getUerInfo(isRefresh: Boolean) = ycLaunch {
        mUserRepository.getUserInfo().ycHasLoading(delayTime = if (isRefresh) 0 else mDefaultDelayTime).collectLatest { result ->
            _mUerInfo.postValue(result)
        }
    }
}


